package com.hw.one.dam2.controller;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.hw.one.core.controller.BaseController;
import com.hw.one.core.result.MsgResult;
import com.hw.one.dam2.service.IWeatherService;

/**
 * 城市天气
 * 
 * @author admin
 *
 */
@RestController
@RequestMapping(value = "weather")
public class WeatherController extends BaseController {

	@Autowired
	private IWeatherService weatherService;
	
	/**
	 * 查询给定 区域 的天气预报
	 * 
	 * @param model
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "findWeatherForecastByRegionCode", method = RequestMethod.GET)
	public MsgResult findWeatherForecastByRegionCode(Model model, HttpServletRequest request) {
		try {
			

			return weatherService.findCityWeatherForecastByRegionCode(request);
		} catch (Exception e) {
			e.printStackTrace();
			return MsgResult.errorResult("查询区域天气预报出现异常，后台程序异常。");
		}
	}
	
	/**
	 * 查询 给定区域的 实时天气
	 * 
	 * @param model
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "findWeatherLiveByRegionCode", method = RequestMethod.GET)
	public MsgResult findWeatherLiveByRegionCode(Model model, HttpServletRequest request) {
		try {
			Map<String,Object> paraMap = new HashMap<String,Object>();
			Object cityLiveWeatherObj = weatherService.findCityLiveWeatherByRegionCode(paraMap);
			
			return MsgResult.okResult(cityLiveWeatherObj);
		} catch (Exception e) {
			e.printStackTrace();
			return MsgResult.errorResult("查询区域实时天气出现异常，后台程序异常。");
		}
	}
	
}
